package com.lmm.lcuser.lc_user.config;

import com.lmm.dresswisdom.lmmframe.util.MD5Utils;

import java.util.Arrays;
import java.util.Map;

/**
 * Created by xmgong on 2016/12/13.
 * 安全模块
 */

public class DataSafeUtil {

    public static Map<String, String> EncodeMAP(Map<String, String> keymaps) {
        Map<String, String> param = keymaps;
        //默认 Map 先加入 api_version
        keymaps.put("api_version", ConfigValue.API_VERSION);
        //取加密 key 排序
        String[] keys = keymaps.keySet().toArray(new String[]{});
        Arrays.sort(keys);

        String sign = "";
        for (int i = 0; i < keys.length; i++) {
            sign += keys[i] + "=" + keymaps.get(keys[i]);
            if (i < keys.length - 1) {
                sign += "&";
            }
        }
        sign += ConfigValue.AppSecret;
        //计算密文
        String sign2 = MD5Utils.getMD5(sign);
        // Map 加入密文
        param.put("sign", sign2);
        return param;
    }
}
